﻿using System;
using Authorit.API.Configuration;
using WordCount.Properties;

namespace WordCount
{
	/// <summary>
	/// Implements support for reading the configuration settings file for the plugin
	/// </summary>
	public class Config
	{
		/// <summary>
		/// Backing field for the <see cref="DataGridClipboardKeepDateAfterExit"/> property
		/// </summary>
		private bool dataGridClipboardKeepDateAfterExit;

		/// <summary>
		/// Backing field for the <see cref="DataGridShowTotalRow"/> property
		/// </summary>
		private bool dataGridShowTotalRow;

		/// <summary>
		/// Backing field for the <see cref="DataGridViewRowHeadersVisible"/> property
		/// </summary>
		private bool dataGridViewRowHeadersVisible;
		
		/// <summary>
		/// Backing field for the <see cref="FormShowIcon"/> property
		/// </summary>
		private bool formShowIcon;

		/// <summary>
		/// Backing field for the <see cref="FormShowInTaskbar"/> property
		/// </summary>
		private bool formShowInTaskbar;

		/// <summary>
		/// Backing field for the <see cref="PluginNameBookEditor"/> property
		/// </summary>
		private string pluginNameBookEditor;

		/// <summary>
		/// Backing field for the <see cref="PluginNameMainForm"/> property
		/// </summary>
		private string pluginNameMainForm;

		/// <summary>
		/// Backing field for the <see cref="ShowVersion"/> property
		/// </summary>
		private bool showVersion;

		/// <summary>
		/// Backing field for the <see cref="TargetGroupNameBookEditor"/> property
		/// </summary>
		private string targetGroupNameBookEditor;

		/// <summary>
		/// Backing field for the <see cref="TargetGroupNameToolbar"/> property
		/// </summary>
		private string targetGroupNameToolbar;

		/// <summary>
		/// Backing field for the <see cref="ToolbarShowButtonImage"/> property
		/// </summary>
		private bool toolbarShowButtonImage;

		/// <summary>
		/// Backing field for the <see cref="ToolbarShowButtonName"/> property
		/// </summary>
		private bool toolbarShowButtonName;

		/// <summary>
		/// Backing field for the <see cref="ToolbarShowButtonTooltip"/> property
		/// </summary>
		private bool toolbarShowButtonTooltip;

		/// <summary>
		/// Initializes a new instance of the <see cref="Config"/> class
		/// </summary>
		/// <seealso cref="ReadConfiguration()"/>
		public Config()
		{
			ReadConfiguration();
		}

		/// <summary>
		/// Gets or sets a value that specifies whether the clipboard retains data copied to it after the user closed the form
		/// </summary>
		public bool DataGridClipboardKeepDateAfterExit
		{
			get { return dataGridClipboardKeepDateAfterExit; }
			set { dataGridClipboardKeepDateAfterExit = value; }
		}

		/// <summary>
		/// Gets or sets a value that specifies whether the results datagrid displays a total row
		/// </summary>
		public bool DataGridShowTotalRow
		{
			get { return dataGridShowTotalRow; }
			set { dataGridShowTotalRow = value; }
		}

		/// <summary>
		/// Gets or sets a value that specifies whether the result datagrid displays row headers
		/// </summary>
		public bool DataGridViewRowHeadersVisible
		{
			get { return dataGridViewRowHeadersVisible; }
			set { dataGridViewRowHeadersVisible = value; }
		}

		/// <summary>
		/// Gets or sets a value that specifies whether the main form displays an icon
		/// </summary>
		public bool FormShowIcon
		{
			get { return formShowIcon; }
			set { formShowIcon = value; }
		}

		/// <summary>
		/// Gets or sets a value that specifies whether the form shows in the taskbar
		/// </summary>
		public bool FormShowInTaskbar
		{
			get { return formShowInTaskbar; }
			set { formShowInTaskbar = value; }
		}

		/// <summary>
		/// Gets or sets the name for the book editor plugin button
		/// </summary>
		public string PluginNameBookEditor
		{
			get { return pluginNameBookEditor; }
			set { pluginNameBookEditor = value; }
		}

		/// <summary>
		/// Gets or sets the name for the main form plugin button
		/// </summary>
		public string PluginNameMainForm
		{
			get { return pluginNameMainForm; }
			set { pluginNameMainForm = value; }
		}

		/// <summary>
		/// Gets or sets a value that specifies whether the form displays the version of the plugin
		/// </summary>
		public bool ShowVersion
		{
			get { return showVersion; }
			set { showVersion = value; }
		}

		/// <summary>
		/// Gets or sets the name of the book editor toolbar group in which the the plugin will display book editor plugin button
		/// </summary>
		public string TargetGroupNameBookEditor
		{
			get { return targetGroupNameBookEditor; }
			set { targetGroupNameBookEditor = value; }
		}

		/// <summary>
		/// Gets or sets the name of the main form toolbar group in which the plugin will display the main form plugin button
		/// </summary>
		public string TargetGroupNameToolbar
		{
			get { return targetGroupNameToolbar; }
			set { targetGroupNameToolbar = value; }
		}

		/// <summary>
		/// Gets or sets a value that specifies whether the main form button displays an image
		/// </summary>
		public bool ToolbarShowButtonImage
		{
			get { return toolbarShowButtonImage; }
			set { toolbarShowButtonImage = value; }
		}

		/// <summary>
		/// Gets or sets a value that specifies whether the main form button displays a text name
		/// </summary>
		public bool ToolbarShowButtonName
		{
			get { return toolbarShowButtonName; }
			set { toolbarShowButtonName = value; }
		}

		/// <summary>
		/// Gets or sets a value that specifies whether the plugin displays a tooltip for the main form button
		/// </summary>
		public bool ToolbarShowButtonTooltip
		{
			get { return toolbarShowButtonTooltip; }
			set { toolbarShowButtonTooltip = value; }
		}

		/// <summary>
		/// Reads the configuration file for the plugin and sets values for the properties
		/// of this instance of the <see cref="Config"/> class.
		/// </summary>
		private void ReadConfiguration()
		{
			this.dataGridClipboardKeepDateAfterExit = ConfigReader.GetSettingAsBoolean(ReflectionUtility.GetPropertyName(() => Settings.Default.DataGridClipboardKeepDateAfterExit));
			this.dataGridShowTotalRow = ConfigReader.GetSettingAsBoolean(ReflectionUtility.GetPropertyName(() => Settings.Default.DataGridShowTotalRow));
			this.dataGridViewRowHeadersVisible = ConfigReader.GetSettingAsBoolean(ReflectionUtility.GetPropertyName(() => Settings.Default.DataGridViewRowHeadersVisible));
			this.formShowIcon = ConfigReader.GetSettingAsBoolean(ReflectionUtility.GetPropertyName(() => Settings.Default.FormShowIcon));
			this.formShowInTaskbar = ConfigReader.GetSettingAsBoolean(ReflectionUtility.GetPropertyName(() => Settings.Default.FormShowInTaskbar));
			this.pluginNameBookEditor = ConfigReader.GetSetting(ReflectionUtility.GetPropertyName(() => Settings.Default.PluginNameBookEditor));
			this.pluginNameMainForm = ConfigReader.GetSetting(ReflectionUtility.GetPropertyName(() => Settings.Default.PluginNameMainForm));
			this.showVersion = ConfigReader.GetSettingAsBoolean(ReflectionUtility.GetPropertyName(() => Settings.Default.ShowVersion));
			this.targetGroupNameBookEditor = ConfigReader.GetSetting(ReflectionUtility.GetPropertyName(() => Settings.Default.TargetGroupNameBookEditor));
			this.targetGroupNameToolbar = ConfigReader.GetSetting(ReflectionUtility.GetPropertyName(() => Settings.Default.TargetGroupNameToolbar));
			this.toolbarShowButtonImage = ConfigReader.GetSettingAsBoolean(ReflectionUtility.GetPropertyName(() => Settings.Default.ToolbarShowButtonImage));
			this.toolbarShowButtonName = ConfigReader.GetSettingAsBoolean(ReflectionUtility.GetPropertyName(() => Settings.Default.ToolbarShowButtonName));
			this.toolbarShowButtonTooltip = ConfigReader.GetSettingAsBoolean(ReflectionUtility.GetPropertyName(() => Settings.Default.ToolbarShowButtonTooltip));
		}
	}
}